﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

public partial class Admin_Login : System.Web.UI.Page
{
    SqlConnection objCon;
    SqlCommand objCom;
    SqlDataReader objdr;
    HttpCookie userInFoCookie;
    protected void Page_Load(object sender, EventArgs e)
    {

        objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["shopgift"].ConnectionString);
        objCon.Open();
        Session["checkLogin"] = "False";
       userInFoCookie = new HttpCookie("infoUser");
      // txtUser.Text = userInFoCookie.Values["User"].ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string user = txtUser.Text;
        string pass = txtPass.Text;
        Session["Username"] = user;
        if (cbRemeber.Checked) {
            userInFoCookie.Values["User"] = user;
            userInFoCookie.Values["Pass"] = pass;
            userInFoCookie.Expires = DateTime.MaxValue;
            Response.Cookies.Add(userInFoCookie);
        
        }
        objCom = new SqlCommand("SELECT * FROM tbl_user WHERE Username='" + user + "' AND Password='" + pass + "' AND Type=1", objCon);

        objdr = objCom.ExecuteReader();

        if (objdr.HasRows)
        {

          

            Session["checkLogin"] = "True";
          
            objCon.Close();
            Response.Redirect("Default.aspx");


        }
        else
        {
            Response.Write("<script>alert('Login Fail');</script>");
            Session["checkLogin"] = "False";
            return;

        }




    }
}